package com.fw.payment.bao;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import java.io.Serializable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fw.payment.service.ServiceExecutor;
import com.fw.payment.service.ServiceOrder;
import com.fw.service.merchanttransactiondata.MerchantTransactionDataService;
import com.fw.service.merchanttransactiondata.bean.MerchantTransactionDataBean;

@Component
@Scope(SCOPE_PROTOTYPE)
public class MerchantTransactionDataBAO extends AbstractBAO implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Autowired
    private MerchantTransactionDataService merchantTransactionDataService;

    public MerchantTransactionDataBean createMerchantTransactionData(MerchantTransactionDataBean merchantTransactionDataBean)
	    throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.merchantTransactionDataService);
	    serviceOrder.setMethodName("createMerchantTransactionData");
	    serviceOrder.setParameterTypes(new Class[] { MerchantTransactionDataBean.class });
	    serviceOrder.setParameterValues(new Object[] { merchantTransactionDataBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		return (MerchantTransactionDataBean) serviceOrder.getReturnValue();
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    public MerchantTransactionDataBean updateMerchantTransactionData(MerchantTransactionDataBean merchantTransactionDataBean)
	    throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.merchantTransactionDataService);
	    serviceOrder.setMethodName("updateMerchantTransactionData");
	    serviceOrder.setParameterTypes(new Class[] { MerchantTransactionDataBean.class });
	    serviceOrder.setParameterValues(new Object[] { merchantTransactionDataBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		return (MerchantTransactionDataBean) serviceOrder.getReturnValue();
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    public MerchantTransactionDataBean getMerchantTransactionDataByInvoiceNo(String invoiceNo) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.merchantTransactionDataService);
	    serviceOrder.setMethodName("getMerchantTransactionDataByInvoiceNo");
	    serviceOrder.setParameterTypes(new Class[] { String.class });
	    serviceOrder.setParameterValues(new Object[] { invoiceNo });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		return (MerchantTransactionDataBean) serviceOrder.getReturnValue();
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    public MerchantTransactionDataBean getMerchantTransactionDataBy(Long id) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.merchantTransactionDataService);
	    serviceOrder.setMethodName("getMerchantTransactionData");
	    serviceOrder.setParameterTypes(new Class[] { Long.class });
	    serviceOrder.setParameterValues(new Object[] { id });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		return (MerchantTransactionDataBean) serviceOrder.getReturnValue();
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }
}
